package com.zzptc.shop.servlet;

import com.zzptc.shop.dao.IDAO;
import com.zzptc.shop.dao.UserDao;
import com.zzptc.shop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "LogServlet")
public class LogServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter pw=response.getWriter();
        //pw.print("login succ");
        //接收用户名和密码
        String username=request.getParameter("userName");   // 获取表单的userName的内容
        String pwd=request.getParameter("passWord");
        Users users=new Users();
        users.setEu_user_name(username);
        users.setEu_password(pwd);

        //调用dao中的登录方法
        IDAO userdao=new UserDao();
        boolean flag=false;
        try {
            ((UserDao) userdao).login(users);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(flag){
            pw.print("login succ welcome");
        }else {
            pw.print("login error");
        }
    }
}
